# coding=utf-8
import logging
import sys
from django.db import connection
reload(sys)
sys.setdefaultencoding('utf-8')

logger = logging.getLogger('django')

def executeQuery(sql):
	'''执行django原始sql语句  并返回一个数组对象'''
	cursor = connection.cursor()  # 获得一个游标(cursor)对象
	logger.info(sql)
	cursor.execute(sql)
	rawData = cursor.fetchall()
	col_names = [desc[0] for desc in cursor.description]
	result = []
	for row in rawData:
		objDict = {}
		# 把每一行的数据遍历出来放到Dict中
		for index, value in enumerate(row):
			objDict[col_names[index]] = value
		result.append(objDict)
	return result

def executeUpdate(sql):
	cursor = connection.cursor()  # 获得一个游标(cursor)对象
	logger.info(sql)
	cursor.execute(sql)
